package com.ruoyi.web.repository;


import com.ruoyi.web.model.C2ApaResourceDetail;
import com.ruoyi.web.model.C2CnidResourceDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ResourceDetailRepository {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    // 查询cnid所有资源详情
    public List<C2CnidResourceDetail> findCnidDetail() {
        String sql = "SELECT id, processname, version, max90, max95, max97, date FROM cnid_source_detail";
        return jdbcTemplate.query(sql, (resultSet, rowNum) -> {
            C2CnidResourceDetail detail = new C2CnidResourceDetail();
            detail.setId(resultSet.getLong("id"));
            detail.setProcessName(resultSet.getString("processname"));
            detail.setVersion(resultSet.getString("version"));
            detail.setMax90(resultSet.getDouble("max90"));
            detail.setMax95(resultSet.getDouble("max95"));
            detail.setMax97(resultSet.getDouble("max97"));
            detail.setDate(resultSet.getDate("date").toLocalDate());
            return detail;
        });
    }

    // 查询apa所有资源详情
    public List<C2ApaResourceDetail> findApaDetail() {
        String sql = "SELECT id, processname, version, max90, max95, max97, date FROM apa_source_detail";
        return jdbcTemplate.query(sql, (resultSet, rowNum) -> {
            C2ApaResourceDetail detail = new C2ApaResourceDetail();
            detail.setId(resultSet.getLong("id"));
            detail.setProcessName(resultSet.getString("processname"));
            detail.setVersion(resultSet.getString("version"));
            detail.setMax90(resultSet.getDouble("max90"));
            detail.setMax95(resultSet.getDouble("max95"));
            detail.setMax97(resultSet.getDouble("max97"));
            detail.setDate(resultSet.getDate("date").toLocalDate());
            return detail;
        });
    }
}